<?php
header('Access-Control-Allow-Origin: *');
header('Content-type: text/plain');

require_once 'aop/AopClient.php';
require_once 'aop/request/AlipayTradeAppPayRequest.php';

// 获取支付金额
$amount='';
if($_SERVER['REQUEST_METHOD']=='POST'){
    $amount=$_POST['total'];
}else{
    $amount=$_GET['total'];
}

$total = floatval($amount);
if(!$total){
    $total = 1;
}

$aop = new AopClient;
$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
$aop->appId = "2018110561994656";
$aop->rsaPrivateKey = "MIIEowIBAAKCAQEAwEE2CdIOU1+jGf+RBksAxdh93XLAOsq7f3nMKT67sCqcrroaZX6sE9t0SiZAv9PzBxrSUME7lJeIqoRF6CdHcaMNvR78QWxl09ir5cY6vL8THR3gD/6OIW11NHjqzXnn0jtvGNHXop6vxxpzi3UoxP7FqhDGxRZQguOXhoIcKKDH7659XJAjbBfQjeGs0bhCrgdqKDqNJEyOPHv1Gw6tHXYD6+F++EFXyoYVV+8zxgIIfVZHUSAYbGx7cwbVw0O6W2jtXfokfK5gF/mJU6l69v9Ns0U9CFabL5/w4Cw585ApEMTzFXRQZxtYUJ2HY4IEF4oJcWUQ+3y3asBXKZFmrwIDAQABAoIBAEhaQlP/0ZRe8arfG10a7PeIOhYVEXMOyPF4jPUYvtnVr5GySCzaNzhh5qnhK40F3vhVh8EMd7e8L5q8nPJ5ldGWY51BA/47JTdM26RlrcVKw465p5FdY3ABGZLdzr/1mODtrSnSDy0MO2ra8ZESTn2UxB70oVmaxEH+FRBx9tbywzeDNbnPuBs+vZ1TV1Yjqri4GVeVJPeSmFvEOmAiIOYVHFJLcd0ApWrlvOQg8HLI4xVttq+mY56ni09IhhqGrbc4T3Pi3mg4k2oP9aMMdWGFxMWGf36dWLqeT7gKH0BwcHpYp7+Vx/LjiyTq4DANxzsm7eooN7FfF31EprKCEMECgYEA+MWYxHWUOF2vF6cWMzzkwVrRVFJykXUbDVnob9nI4SARgABdYM96zv05jg9pjac/JdkFlRIQd6JcgstQ6K8emWlR47WZ3baS75bItct3ER9XXJfaI/pYBriiLZ4lbcq1imFKUddF2+GsXoOBDzZi3FBtKUjNznodpSS+4DSRkUMCgYEAxdc7Mz7HleninDZAF5VgU0cPCXdNSq+Hsg8zt10K/yNHGHpB5Rvg/2xyOp8msPWPwdwwr0jOfnFuHR6+lsXK3bVT//tjUzJ6z2MuAZX1iykqKPTFzdqgwY3AykADu4aa1rSy0tAZ8zoqqFaObMUZRGphc8kJKn3QPZKwIZrQeCUCgYEA1i/66ht59FXk7O51VMQ3CKsS1BDwh4BWPFaOo87U/8/GgXjO7Q12ZUTtCv0GGmpHGmUSQ1j8SKTIFezLyqsMI3XkhbPTuGr7c8FVKgD2kQ11AEnWDWf75j2NlM022KLRT0WY4YIBqeFRsUZ0Fg7za1Dry8HdQMsvPwK2PP/F3VUCgYB3Tr6yvq9Z5rvz/HtWPYzja7zTtpBz87rfVG+ZqpCRIFMlncTTR6a+IkYYuBV7LftNq13otv1gH0OKaBoDjrAyV8GaY52YdJ6/Jk5+QlLbYy27mTEYXToIv1V+InCdzCTgSgR1QW4E0hUbg2dMjOgZ7BVs39WZPFoyZ520BkqlyQKBgEhii64n0BFxrITdAyiCRyklwKVs79CL/qxcPSB/WHJqM6438jeDgbKrEMsZEf98CognvF4Ad+Jfwu9lRRYr6PPgpubC9tO6tQGFle9D8UJrl6xf1zO7XUSp3cheEP0KC33eOV7RcIyXiPd7xulKoSxCql/bV3pyyQnvS56XON5n";//'请填写开发者私钥去头去尾去回车，一行字符串';

$aop->format = "json";
$aop->charset = "UTF-8";
$aop->signType = "RSA2";
$aop->alipayrsaPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwEE2CdIOU1+jGf+RBksAxdh93XLAOsq7f3nMKT67sCqcrroaZX6sE9t0SiZAv9PzBxrSUME7lJeIqoRF6CdHcaMNvR78QWxl09ir5cY6vL8THR3gD/6OIW11NHjqzXnn0jtvGNHXop6vxxpzi3UoxP7FqhDGxRZQguOXhoIcKKDH7659XJAjbBfQjeGs0bhCrgdqKDqNJEyOPHv1Gw6tHXYD6+F++EFXyoYVV+8zxgIIfVZHUSAYbGx7cwbVw0O6W2jtXfokfK5gF/mJU6l69v9Ns0U9CFabL5/w4Cw585ApEMTzFXRQZxtYUJ2HY4IEF4oJcWUQ+3y3asBXKZFmrwIDAQAB";//'请填写支付宝公钥，一行字符串';

//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
$request = new AlipayTradeAppPayRequest();

// 异步通知地址
$notify_url = 'http://sl.acg-fan.com/alipayrsa2/notify.php';
// var_dump($notify_url);die();
// 订单标题
$subject = 'DCloud项目捐赠';
// 订单详情
$body = 'DCloud致力于打造HTML5最好的移动开发工具，包括终端的Runtime、云端的服务和IDE，同时提供各项配套的开发者服务。'; 
// 订单号，示例代码使用时间值作为唯一的订单ID号

$out_trade_no = date('YmdHis', time());
// $out_trade_no = "1541556277";
//SDK已经封装掉了公共参数，这里只需要传入业务参数
$bizcontent = "{\"body\":\"".$body."\","
                . "\"subject\": \"".$subject."\","
                . "\"out_trade_no\": \"".$out_trade_no."\","
                . "\"timeout_express\": \"30m\","
                . "\"total_amount\": \"".$total."\","
                . "\"product_code\":\"QUICK_MSECURITY_PAY\""
                . "}";
$request->setNotifyUrl($notify_url);
$request->setBizContent($bizcontent);
//这里和普通的接口调用不同，使用的是sdkExecute
$response = $aop->sdkExecute($request);




// 注意：这里不需要使用htmlspecialchars进行转义，直接返回即可
echo $response;


/*	
	异步通知说明
	https://docs.open.alipay.com/59/103666/
	支付宝返回参数
	{"gmt_create":"2018-11-07 10:00:17","charset":"UTF-8","seller_email":"zlmyong@163.com","subject":"DCloud\u9879\u76ee\u6350\u8d60","sign":"fnz5YCRylnupMh1dJgEkwDlfB1N1SY5AoJbv+jwTsNW9wfyRZtnYFkFpTMBv3SSrzrWMgUCAtiEnNVbxcelarGhTudbxKwFYKhZ7IPb0Fg0SfRyS6bDYAtuc1GKmatreu\/0ehjHdY5t\/1xZx9G9EUmnZxqxvi0varH8S05KyOuQrz1F+ffjvrkjO4LRJz8GtgspMAP6qYyBglmYxeNZQArNxG7nLzpY5W0LiaowmuRywHjwFy4xJCB\/Zk4EJ2Z8CVbP+hYTN9rRnjpjTR+x\/dRm93qYVEChRTv+ojVehHNRXoNkhUwwQ+8hk2XfvnLi3przNEZKRwndSIe558ZxB+g==","body":"DCloud\u81f4\u529b\u4e8e\u6253\u9020HTML5\u6700\u597d\u7684\u79fb\u52a8\u5f00\u53d1\u5de5\u5177\uff0c\u5305\u62ec\u7ec8\u7aef\u7684Runtime\u3001\u4e91\u7aef\u7684\u670d\u52a1\u548cIDE\uff0c\u540c\u65f6\u63d0\u4f9b\u5404\u9879\u914d\u5957\u7684\u5f00\u53d1\u8005\u670d\u52a1\u3002","buyer_id":"2088112893845612","invoice_amount":"0.01","notify_id":"2018110700222100017045611020178922","fund_bill_list":"[{\"amount\":\"0.01\",\"fundChannel\":\"ALIPAYACCOUNT\"}]","notify_type":"trade_status_sync","trade_status":"TRADE_SUCCESS","receipt_amount":"0.01","app_id":"2018110561994656","buyer_pay_amount":"0.01","sign_type":"RSA2","seller_id":"2088331351871220","gmt_payment":"2018-11-07 10:00:17","notify_time":"2018-11-07 10:00:18","version":"1.0","out_trade_no":"1541556277","total_amount":"0.01","trade_no":"2018110722001445611005903866","auth_app_id":"2018110561994656","buyer_logon_id":"188****8946","point_amount":"0.00"}

*/
?>